//
//  PurchaseOrderTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/12.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "PurchaseOrderTableViewCell.h"

@interface PurchaseOrderTableViewCell ()

@property (strong, nonatomic) UIImageView *timeIV;
@property (strong, nonatomic) UILabel *timeL;
@property (strong, nonatomic) UILabel *statusL;
@property (strong, nonatomic) UIImageView *goodsIV;
@property (strong, nonatomic) UILabel *nameL;
@property (strong, nonatomic) UIImageView *moneyLogoIV;
@property (strong, nonatomic) UILabel *moneyL;
@property (strong, nonatomic) UIImageView *countIV;
@property (strong, nonatomic) UILabel *countL;
@property (strong, nonatomic) UILabel *totolMoneyL;

@property (strong, nonatomic) UIImageView *cancleOrderIV;
@property (strong, nonatomic) UILabel *cancleOrderL;

@property (strong, nonatomic) UIImageView *payOrderIV;
@property (strong, nonatomic) UILabel *payOrderL;

@property (strong, nonatomic) UIImageView *lineIV;

@property (strong, nonatomic) UILabel *rankL;

@end;

@implementation PurchaseOrderTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.timeIV];
        [self.contentView addSubview:self.timeL];
        [self.contentView addSubview:self.statusL];
        [self.contentView addSubview:self.goodsIV];
        [self.contentView addSubview:self.nameL];
        [self.contentView addSubview:self.moneyLogoIV];
        [self.contentView addSubview:self.moneyL];
        [self.contentView addSubview:self.countIV];
        [self.contentView addSubview:self.countL];
        [self.contentView addSubview:self.totolMoneyL];
        [self.contentView addSubview:self.cancleOrderIV];
        [self.contentView addSubview:self.cancleOrderL];
        [self.contentView addSubview:self.payOrderIV];
        [self.contentView addSubview:self.payOrderL];
        [self.contentView addSubview:self.lineIV];
        
        [self.contentView addSubview:self.rankL];
        
    }
    
    return self;

}

- (void)setDict:(NSDictionary *)dict {
    
    _dict = dict;
    
    if (self.type == 0) {
        
        self.rankL.hidden = YES;
    
    }else if (self.type == 1) {
        
        self.cancleOrderL.hidden = YES;
        self.cancleOrderIV.hidden = YES;
        
        self.payOrderL.text = @"再次购买";
        
    }else {
        
        self.rankL.hidden = YES;
        
        self.cancleOrderL.hidden = YES;
        self.cancleOrderIV.hidden = YES;
        
        self.payOrderL.text = @"再次购买";
    }
   
}

#pragma mark -取消订单
- (void)cancleGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"取消订单");
    
}

#pragma mark -立即支付
- (void)payOrderGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"立即支付");
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
}

- (void)layoutSubviews {
    
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *v in control.subviews)
            {
                if ([v isKindOfClass: [UIImageView class]]) {
                    UIImageView *img=(UIImageView *)v;
                    if (self.selected) {
                        //选中时图片
                        img.image=[UIImage imageNamed:@"cellSelceted"];
                    }else
                    {
                        //未选中时图片
                        img.image=[UIImage imageNamed:@"notSelected"];
                    }
                }
            }
        }
    }

    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.timeIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(50));
        make.width.mas_equalTo(jisuan(30));
        make.height.mas_equalTo(jisuan(30));
    
    }];
    
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.timeIV.mas_right).with.offset(Margin);
        make.centerY.mas_equalTo(weakSelf.timeIV.mas_centerY);

    }];
    
    [self.statusL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.timeIV.mas_centerY);

    }];
    
    [self.goodsIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.timeIV.mas_bottom).with.offset(jisuan(22));
        make.width.mas_equalTo(jisuan(120));
        make.height.mas_equalTo(jisuan(120));
    
    }];
    
    [self.moneyL sizeToFit];
    [self.moneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.statusL.mas_bottom).with.offset(jisuan(20));
        
        if (self.moneyL.text) {
            
            make.width.mas_equalTo(weakSelf.moneyL.width);
            make.height.mas_equalTo(weakSelf.moneyL.height);
        }
        
    }];
    
    [self.moneyLogoIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.moneyL.mas_left).with.offset(-jisuan(10));
        make.centerY.mas_equalTo(weakSelf.moneyL.mas_centerY);
        make.width.mas_equalTo(jisuan(14));
        make.height.mas_equalTo(jisuan(18));
    }];
    
    [self.nameL sizeToFit];
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.goodsIV.mas_right).with.offset(jisuan(30));
        make.top.mas_equalTo(weakSelf.goodsIV.mas_top);
        make.right.mas_equalTo(weakSelf.moneyLogoIV.mas_left).with.offset(-jisuan(30));
        

    }];
    [self.rankL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.nameL.mas_left);
        make.bottom.mas_equalTo(weakSelf.goodsIV.mas_bottom);
    }];
    
    
    [self.countL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.moneyL.mas_bottom).with.offset(jisuan(22));
        
    }];
    [self.countIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.countL.mas_left).with.offset(-jisuan(10));
        make.centerY.mas_equalTo(weakSelf.countL.mas_centerY);
        make.width.mas_equalTo(jisuan(14));
        make.height.mas_equalTo(jisuan(14));
        
    }];
    
    [self.totolMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(96));
        
    }];
    
    [self.payOrderIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(30));
        make.width.mas_equalTo(jisuan(156));
        make.height.mas_equalTo(jisuan(46));
        
    }];
    
    [self.payOrderL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.payOrderIV.mas_centerY);
        make.centerX.mas_equalTo(weakSelf.payOrderIV.mas_centerX);
        
    }];
    
    [self.cancleOrderIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.payOrderIV.mas_left).with.offset(-jisuan(30));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(30));
        make.width.mas_equalTo(jisuan(156));
        make.height.mas_equalTo(jisuan(46));
        
    }];
    
    [self.cancleOrderL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.cancleOrderIV.mas_centerY);
        make.centerX.mas_equalTo(weakSelf.cancleOrderIV.mas_centerX);
        
    }];
    
    [self.lineIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.centerX.mas_equalTo(weakSelf.contentView.mas_centerX);
        make.width.mas_equalTo(jisuan(714));
        make.height.mas_equalTo(jisuan(4));
    }];
}

#pragma mark -lazy
- (UIImageView *)timeIV {
    
    if (!_timeIV) {
        
        _timeIV = [[UIImageView alloc] init];
        _timeIV.contentMode = UIViewContentModeScaleAspectFit;
        _timeIV.image = [UIImage imageNamed:@"timeBG"];
        
    }
    
    return _timeIV;
}

- (UILabel *)timeL {
    
    if (!_timeL) {
        
        _timeL = [[UILabel alloc] init];
        _timeL.textColor = Color333333;
        _timeL.text = @"2018-06-29 15:12:23";
        _timeL.font = Font(24);
        _timeL.textAlignment = NSTextAlignmentLeft;
        _timeL.backgroundColor = WhiteColor;
        
    }
    
    return _timeL;
}

- (UILabel *)statusL {
    
    if (!_statusL) {
        
        _statusL = [[UILabel alloc] init];
        _statusL.textColor = Colorff4200;
        _statusL.text = @"等待支付";
        _statusL.font = Font(24);
        _statusL.textAlignment = NSTextAlignmentRight;
        _statusL.backgroundColor = WhiteColor;
        
    }
    
    return _statusL;
}

- (UIImageView *)goodsIV {
    
    if (!_goodsIV) {
        
        _goodsIV = [[UIImageView alloc] init];
        _goodsIV.contentMode = UIViewContentModeScaleAspectFit;
        _goodsIV.image = [UIImage imageNamed:@"goodsBG"];
    }
    
    return _goodsIV;
}

- (UILabel *)nameL {
    
    if (!_nameL) {
        
        _nameL = [[UILabel alloc] init];
        _nameL.textColor = Color333333;
        
        NSString *str = @"理财红包，十块钱;理财红包，十块钱;理财红包，十块钱;理财红包，十块钱;理财红包，十块钱";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *pargStyle = [[NSMutableParagraphStyle alloc] init];
        [pargStyle setLineSpacing:jisuan(5)];
        [attributeStr addAttribute:NSParagraphStyleAttributeName value:pargStyle range:NSMakeRange(0, str.length)];
        _nameL.attributedText = attributeStr;
        _nameL.numberOfLines = 2;
        _nameL.lineBreakMode = NSLineBreakByCharWrapping;
        
        _nameL.font = Font(24);
        _nameL.textAlignment = NSTextAlignmentLeft;
        _nameL.backgroundColor = WhiteColor;
        
    }
    
    return _nameL;
}

- (UILabel *)moneyL  {
    
    if (!_moneyL) {
        
        _moneyL = [[UILabel alloc] init];
        _moneyL.textColor = Color333333;
        _moneyL.text = @"99999.00";
        _moneyL.font = Font(24);
        _moneyL.textAlignment = NSTextAlignmentRight;
        _moneyL.backgroundColor = WhiteColor;
    
    }
    
    return _moneyL;
    
}

- (UIImageView *)moneyLogoIV {
    
    if (!_moneyLogoIV) {
        
        _moneyLogoIV = [[UIImageView alloc] init];
        _moneyLogoIV.contentMode = UIViewContentModeScaleAspectFit;
        _moneyLogoIV.image = [UIImage imageNamed:@"moneyLogoBG"];
    }
    
    return _moneyLogoIV;
    
}

- (UILabel *)countL {
    
    if (!_countL) {
        
        _countL = [[UILabel alloc] init];
        _countL.textColor = Color9b9b9b;
        _countL.text = @"1";
        _countL.font = Font(24);
        _countL.textAlignment = NSTextAlignmentRight;
        
        _countL.backgroundColor = WhiteColor;
    }
    
    return _countL;
    
}
- (UIImageView *)countIV {
    
    if (!_countIV) {
        
        _countIV = [[UIImageView alloc] init];
        _countIV.contentMode = UIViewContentModeScaleAspectFit;
        _countIV.image = [UIImage imageNamed:@"countOrderBG"];
    }
    
    return _countIV;
    
}

- (UILabel *)totolMoneyL {
    
    if (!_totolMoneyL) {
        
        _totolMoneyL = [[UILabel alloc] init];
        _totolMoneyL.textColor = Color333333;
        _totolMoneyL.text = @"合计：10.00元";
        _totolMoneyL.font = Font(24);
        _totolMoneyL.textAlignment = NSTextAlignmentRight;
        _totolMoneyL.backgroundColor = WhiteColor;
    }
    
    return _totolMoneyL;
    
}

- (UIImageView *)cancleOrderIV {
    
    if (!_cancleOrderIV) {
        
        _cancleOrderIV = [[UIImageView alloc] init];
        _cancleOrderIV.contentMode = UIViewContentModeScaleAspectFit;
        _cancleOrderIV.image = [UIImage imageNamed:@"canclePurchaseBG"];
        
        _cancleOrderIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *cancleGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancleGestureClick:)];
        [_cancleOrderIV addGestureRecognizer:cancleGesture];
    }
    
    return _cancleOrderIV;
}
- (UILabel *)cancleOrderL {
    
    if (!_cancleOrderL) {
        
        _cancleOrderL = [[UILabel alloc] init];
        _cancleOrderL.text = @"取消订单";
        _cancleOrderL.textColor = Color333333;
        _cancleOrderL.font = Font(24);
        _cancleOrderL.textAlignment = NSTextAlignmentCenter;
        _cancleOrderL.backgroundColor = WhiteColor;
        
    }
    
    return _cancleOrderL;
}

- (UIImageView *)payOrderIV {
    
    if (!_payOrderIV) {
        
        _payOrderIV = [[UIImageView alloc] init];
        _payOrderIV.contentMode = UIViewContentModeScaleAspectFit;
        _payOrderIV.image = [UIImage imageNamed:@"purchasePayBG"];
        
        _payOrderIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *payOrderGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(payOrderGestureClick:)];
        [_payOrderIV addGestureRecognizer:payOrderGesture];
        
    }
    
    return _payOrderIV;
}
- (UILabel *)payOrderL {
    
    if (!_payOrderL) {
        
        _payOrderL = [[UILabel alloc] init];
        _payOrderL.textAlignment = NSTextAlignmentCenter;
        _payOrderL.textColor = WhiteColor;
        _payOrderL.text = @"立即支付";
        _payOrderL.font = Font(24);
        
    }
    
    return _payOrderL;
}
- (UILabel *)rankL {
    
    if (!_rankL) {
        
        _rankL = [[UILabel alloc] init];
        _rankL.textAlignment = NSTextAlignmentLeft;
        _rankL.textColor = Color1f89ff;
        _rankL.text = @"当前排位：10";
        _rankL.font = Font(20);
        
    }
    
    return _rankL;
}

- (UIImageView *)lineIV {
    
    if (!_lineIV) {
        
        _lineIV = [[UIImageView alloc] init];
        _lineIV.contentMode = UIViewContentModeScaleAspectFit;
        _lineIV.image = [UIImage imageNamed:@"purchaseLineBG"];
        
    }
    
    return _lineIV;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


@end
